import 'package:flutter/foundation.dart';
import 'package:loxen/mode/mine/user_info_edit.dart';
import 'package:rxdart/rxdart.dart';
import 'package:loxen/api/api.dart';
import 'package:loxen/mode/base_mode.dart';
import 'package:loxen/mode/mine/mine_information_mode.dart';

mixin UserInfoMixin {
  //201
  Stream<int> userLike(int id) {
    return ApiService.userLike(id.toString())
        .flatMap((value) => Stream.value(value.statusCode));
  }

  //200
  Stream<int> unUserLike(int id) {
    return ApiService.userLike(id.toString(), delete: true)
        .flatMap((value) => Stream.value(value.statusCode));
  }

  Stream<MineInformation> userInfo({String id = '0'}) {
    return ApiService.userInfoDetail(id)
        .flatMap((value) => compute(decodeMineInfoData, value.data).asStream())
        .flatMap((value) => Stream.value(value.data));
  }

  Stream<UserInfoEdit> userData({String userId = '0'}) {
    return ApiService.userInfoEdit(userId)
        .flatMap((value) => compute(decodeUserInfoEdit, value.data).asStream())
        .flatMap((value) => Stream.value(value.data));
  }

  static BaseMode<UserInfoEdit> decodeUserInfoEdit(dynamic json) {
    return BaseMode<UserInfoEdit>(json);
  }

  static BaseMode<MineInformation> decodeMineInfoData(dynamic json) {
    return BaseMode<MineInformation>(json);
  }
}
